package com.fang.task;

import org.springframework.core.io.ClassPathResource;

import java.io.*;

public class ClassResourceTest {
    public static void main(String[] args) throws IOException {
        ClassPathResource classPathResource = new ClassPathResource("gdtregion.json");
        InputStream gdtin = classPathResource.getInputStream();
        String gdtjsonTxt = readFile(gdtin);
        System.out.println("JSON:" + gdtjsonTxt);
    }

    private static String readFile ( InputStream inputStream ) throws IOException {
        StringBuilder builder = new StringBuilder();
        try {
            InputStreamReader reader = new InputStreamReader(inputStream , "UTF-8" );
            BufferedReader bfReader = new BufferedReader( reader );
            String tmpContent = null;
            while ( ( tmpContent = bfReader.readLine() ) != null ) {
                builder.append( tmpContent );
            }
            bfReader.close();
        } catch ( UnsupportedEncodingException e ) {
            e.printStackTrace();
        }
        return builder.toString();
    }
}
